import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { OrdersPaginationDto } from './dto/orders-pagination.dto';
import { FindDataDto } from './dto/find-data.dto';
import { OrderDto } from './dto/order.dto';

@Injectable({
  providedIn: 'root',
})
export class OrdersService {
  constructor(private http: HttpClient) {}

  /**
   * 查询一些订单
   * @param usersPaginationDto 分页
   */
  find(ordersPaginationDto: OrdersPaginationDto) {
    const { pageIndex, pageSize, keyword } = ordersPaginationDto;
    return this.http.get<FindDataDto<OrderDto>>('orders', {
      params: {
        pageIndex: pageIndex.toString(),
        pageSize: pageSize.toString(),
        keyword,
      },
    });
  }

  /**
   * 通过用户 _id 删除订单
   * @param _id 订单 _id
   */
  // tslint:disable-next-line: variable-name
  deleteById(_id: string) {
    return this.http.delete(`orders/${_id}`);
  }
}
